package com.itheima.demo;

import java.io.File;
import java.util.HashMap;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/10 19:06
 */
public class Demo_004 {
    public static void main(String[] args) {
        //判断一个文件中有各种类型的文件分别多少个;
        File file = new File("demo_IO");
        HashMap<String, Integer> map = new HashMap<>();
        getCount(map, file);
        map.forEach((key,value)-> System.out.println(key+"..."+value));
    }

    private static void getCount(HashMap<String, Integer> map, File file) {
        if (file == null) {
            return;
        }
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isFile()) {
                String filename = f.getName();
                String[] name = filename.split("\\.");
                //判断集合中后缀名是否存在;
                if(map.containsKey(name[1])){
                    map.put(name[1],map.get(name[1])+1);
                }else{
                    map.put(name[1],1);
                }

            } else {
                getCount(map, f);
            }
        }
    }
}
